package com.crud.filter;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class BootInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest req, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("------------------------执行了--IndexCarTotalInterceptor---设置购物车数量的拦截器--------------------------------------");
        long begin_nao_time = System.nanoTime();
        req.setAttribute("begin_nao_time", begin_nao_time);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest req, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest req, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        long begin_nao_time = (Long) req.getAttribute("begin_nao_time");
        long interval = System.nanoTime() - begin_nao_time;
        System.out.println("响应时间:" + interval);
    }
}